<template>
    <div class="level">
        <div class="title">医院</div>
        <div class="content">
            <div class="left">等级：</div>
            <ul>
                <li :class="{ active: activeFlag == '' }" @click="changeLevel('')">全部</li>
                <li v-for="level in levelArr" :key="level.value" @click="changeLevel(level.value)"
                    :class="{ active: activeFlag == level.value }">{{ level.name }}
                </li>
            </ul>
        </div>
    </div>
</template>

<script setup lang="ts">
import { getHospitalLevelAndRegionAPI } from '@/api/home';
import type { HospitalLevelAndRegionArr, HospitalLevelAndRegponseData } from '@/api/home/type';
import { onMounted, ref } from 'vue';

onMounted(() => {
    getLevel()
})

//存储医院等级数据
let levelArr = ref<HospitalLevelAndRegionArr>([])
//获取医院等级的数据
const getLevel = async () => {
    let result: HospitalLevelAndRegponseData = await getHospitalLevelAndRegionAPI('HosType')
    if (result.code == 200) {
        levelArr.value = result.data
    }
}

//控制医院等级高亮
let activeFlag = ref<string>('')

//点击等级的按钮的回调
const changeLevel = (level: string) => {
    activeFlag.value = level
    //触发自定义事件
    $emit('getLevel',level)
}

let $emit =defineEmits(['getLevel'])
</script>

<style scoped lang="scss">
.level {
    color: #7f7f7f;

    .title {
        font-weight: 900;
        margin: 10px 0
    }

    .content {
        display: flex;

        .left {
            margin-right: 10px;
        }

        ul {
            display: flex;

            li {
                margin-right: 10px;

                &.active {
                    color: #55a6fe;
                }
            }

            li:hover {
                color: #55a6fe;
                cursor: pointer;
            }
        }
    }
}
</style>